package com.gxa.meiye.portal.controller.zy;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gxa.meiye.core.common.JsonResult;
import com.gxa.meiye.core.pojo.domain.Consumer;
import com.gxa.meiye.core.utils.TencentCOSUtil;

import com.gxa.meiye.portal.hread.UserThreadLocal;
import com.gxa.meiye.portal.service.zy.LocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @Author: zy
 * @CreateTime: 2022-07-21  16:39
 */
@RestController
@Api(value = "上传",tags = "上传及查看接口")
@RequestMapping("/locationcha")
public class UpdateChaController {
    @Autowired
  private LocationService locationService;
    @PostMapping("/add")
    public Map location(MultipartFile file,String nickName) throws JsonProcessingException {
        Object o = UserThreadLocal.get();
        ObjectMapper objectMapper=new ObjectMapper();
        Consumer consumer = objectMapper.readValue(o.toString(), Consumer.class);
        String phone = consumer.getPhone();
        System.out.println(phone);
        String img = TencentCOSUtil.uploadfile(file);
        System.out.println(img);
        locationService.add(phone,img,nickName);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setMsg("成功");
        return jsonResult.getMap();
    }
    @ApiOperation(value = "获取select")
    @PostMapping("/select")
    public Map select() throws JsonProcessingException {
        //从本地线程池获取图片
        Object o = UserThreadLocal.get();
        ObjectMapper objectMapper=new ObjectMapper();
        Consumer consumer = objectMapper.readValue(o.toString(), Consumer.class);
        String phone = consumer.getPhone();
        System.out.println(phone);
        Map select = locationService.select(phone);
        JsonResult jsonResult=new JsonResult();
        if (!StringUtils.isEmpty(select)){
            jsonResult.setCode("1");
            jsonResult.setData(select);
        }
        return jsonResult.getMap();
    }
}
